package zuoye11_11;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Guanli {
		List<Students> list = new ArrayList<Students>();

		public void show() {
			System.out.println("学号\t年龄\t姓名\t身份证");
			for (int i = 0; i < list.size(); i++) {
				Students info = list.get(i);
				System.out.println(info.getStuNumber() + "\t" + info.getAge()
						+ "\t" + info.getName() + "\t" + info.getIDNumber());
			}
		}

		public boolean remove(String number) {
			for (int i = 0; i < list.size(); i++) {
				Students a = list.get(i);
				if (a.getStuNumber().equals(number)) {
					list.remove(i);
					return true;
				}
			}
			return false;
		}

		public boolean addStu(Students stu) {
			for (int i = 0; i < list.size(); i++) {
				Students a = list.get(i);
				if (a.getStuNumber().equals(stu.getStuNumber())) {
					return false;
				}
			}
			list.add(stu);
			return true;
		}

		public boolean modify(String number) {
			Scanner input = new Scanner(System.in);
			for (int i = 0; i < list.size(); i++) {
				Students a = list.get(i);
				if (a.getStuNumber().equals(number)) {
					System.out.print("请输入年龄：");
					String ageStr = input.nextLine();
					if (ageStr.length() != 0) {
						int age = Integer.parseInt(ageStr);
						a.setAge(age);
					}
					System.out.print("请输入姓名：");
					String name = input.nextLine();
					if (name.length() != 0) {
						a.setName(name);
					}
					System.out.print("请输入身份证号:");
					String IDNumber = input.nextLine();
					if (IDNumber.length() != 0) {
						a.setIDNumber(IDNumber);
					}
					return true;
				}
			}
			return false;
		}

		public void input() {
			ObjectInputStream obin = null;
			try {
				obin = new ObjectInputStream(new FileInputStream(
						"E:\\Documents\\League of Legends\\Replays\\jj.txt.txt"));
				ArrayList<Students> stu = (ArrayList<Students>) obin.readObject();
				list = stu;
			} catch (Exception e) {
				System.out.println("请先添加内容！");
			} finally {
				try {
					if (obin != null) {
						obin.close();
					}
				} catch (IOException e) {

					e.printStackTrace();
				}
			}

		}

		public void output() {
			ObjectOutputStream obot = null;
			try {
				obot = new ObjectOutputStream(new FileOutputStream(
						"E:\\Documents\\League of Legends\\Replays\\jj.txt.txt"));

				obot.writeObject(list);
			} catch (Exception e) {

				e.printStackTrace();
			} finally {
				try {
					obot.close();
				} catch (IOException e) {

					e.printStackTrace();
				}
			}
		}
	

}
